// 测试 electron-store 的读写
import Store from 'electron-store';
import path from 'path';
import os from 'os';

console.log('=============== Node.js 环境中的 electron-store 测试 ===============');

// 测试默认配置
const defaultStore = new Store();
console.log('默认 Store 路径:', defaultStore.path);
console.log('默认 Store 内容:', defaultStore.store);

// 测试命名 Store
const commentCyclesStore = new Store({
  name: 'comment-cycles',
  defaults: {}
});

const postingIntervalsStore = new Store({
  name: 'posting-intervals',
  defaults: {}
});

console.log('评论周期存储路径:', commentCyclesStore.path);
console.log('发帖间隔存储路径:', postingIntervalsStore.path);

// 测试读取数据
console.log('评论周期数据:', commentCyclesStore.store);
console.log('发帖间隔数据:', postingIntervalsStore.store);

// 测试特定键
const specificCommentKey = 'threads_comment_samep45223';
console.log(`特定评论键 ${specificCommentKey}:`, commentCyclesStore.get(specificCommentKey));

// 读取 Electron 主进程创建的测试键
console.log('测试键:', commentCyclesStore.get('test_main_process_key'));

// 测试自定义目录
const customPathStore = new Store({
  name: 'comment-cycles',
  cwd: path.join(os.homedir(), '.config')
});

console.log('自定义路径存储:', customPathStore.path);
console.log('自定义路径数据:', customPathStore.store);

// 创建一个测试键
commentCyclesStore.set('test_node_script_key', {
  timestamp: Date.now(),
  message: '这是 Node 脚本创建的测试键'
});

console.log('=============== 测试完成 ===============');